package com.yunmai11.yunmai;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.RadioGroup;

import com.yunmai11.yunmai.fragment.BaseFragment;
import com.yunmai11.yunmai.fragment.ChatFragment;
import com.yunmai11.yunmai.fragment.HomeFragment;
import com.yunmai11.yunmai.fragment.UCFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/1/15.
 */
public class HomeActivity extends FragmentActivity implements RadioGroup.OnCheckedChangeListener {
    private RadioGroup rg;
    private List<BaseFragment> fragments;
    private FragmentTransaction ft;
    private int position;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);

        initFragments();
        initView();
    }

    private void initFragments() {
        fragments = new ArrayList<BaseFragment>();
        fragments.add(new HomeFragment());
        fragments.add(new ChatFragment());
        fragments.add(new UCFragment());
    }

    private void initView() {
        rg = (RadioGroup) findViewById(R.id.rg);
        rg.setOnCheckedChangeListener(this);
        rg.check(R.id.rb_home);
    }


    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.rb_home:
                position = 0;
                break;
            case R.id.rb_chat:
                position = 1;
                break;
            case R.id.rb_my:
                position = 2;
                break;
            default:
                position = 0;
                break;
        }

        FragmentManager fm = getSupportFragmentManager();
        ft = fm.beginTransaction();
        ft.replace(R.id.fl_fragment,fragments.get(position));
        ft.commit();
    }
}
